﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AMS.Core.Services;
using AMS.Core.Data;
using AMS.Core;
using System.ServiceModel;
using AMS.DD35.WcfConnector.DD35Service;

namespace AMS.DD35.WcfConnector
{
    public class RegisterProxy : IRegisterService
    {
        private DD35MasterServiceClient _dd35service;

        public RegisterProxy()
        {
            RestartConnection();
        }

        public void AttemptRegister(RegistrationData data)
        {
            try
            {
                _dd35service.AttemptRegister(data);
            }
            catch (FaultException)
            {
                RestartConnection();
                ExceptionHandler.Exception("registration failed");
            }
            // what was the other "connection screwed up" exception?  Started with "C" I think...
            // consider use of FaultException<T> in order to not break connection?
        }

        private void RestartConnection()
        {
            _dd35service = new DD35MasterServiceClient("WS2007HttpBinding_IDD35MasterService");
        }
    }
}
